﻿using log4net;
using Prism.Ioc;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Media3D;
using System.Windows.Threading;

namespace System
{
    public class WinApiHelper
    {
        #region const
        //flags 参数可选值:
        public const int SWP_NOSIZE = 0x0001;//忽略 cx、cy, 保持大小
        public const int SWP_NOMOVE = 0x0002;//忽略 X、Y, 不改变位置
        public const int SWP_NOZORDER = 0x0004;//忽略 hWndInsertAfter, 保持 Z 顺序
        public const int SWP_NOREDRAW = 0x0008;//不重绘
        public const int SWP_NOACTIVATE = 0x0010;//不激活
        public const int SWP_FRAMECHANGED = 0x0020;//{强制发送 WM_NCCALCSIZE 消息, 一般只是在改变大小时才发送此消息
        public const int SWP_SHOWWINDOW = 0x0040;//显示窗口
        public const int SWP_HIDEWINDOW = 0x0080;//隐藏窗口
        public const int SWP_NOCOPYBITS = 0x0100;
        public const int SWP_NOOWNERZORDER = 0x0200;
        public const int SWP_NOSENDCHANGING = 0x0400;
        public const int TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE; //Topmost

        //nCmdShow 参数可选值:
        public const int SW_HIDE = 0; 　　          //从任务栏隐藏
        public const int SW_SHOWNORMAL = 1;         //用最近的大小和位置显示, 激活
        public const int SW_SHOWMIN = 2;            //最大化, 激活
        public const int SW_SHOWMAX = 3;            //最大化, 激活
        public const int SW_SHOWNOACTIVATE = 4;     //用最近的大小和位置显示, 不激活
        public const int SW_SHOW = 5; 　　          //用最近的大小和位置显示, 不激活
        public const int SW_MIN = 6; 　　           //同 SW_SHOWNORMAL
        public const int SW_MAX= 6; 　　            //最小化, 不激活
        public const int SW_RESTORE = 9;            //同 SW_SHOWNORMAL
        public const int SW_SHOWDEFAULT = 10;       //同 SW_SHOWNORMAL

        //hWndInsertAfter 参数可选值:
        public const int HWND_TOP = 0; //在前面
        public const int HWND_BOTTOM = 1; //在后面
        public const int HWND_TOPMOST = -1; //在前面, 位于任何顶部窗口的前面
        public const int HWND_NOTOPMOST = -2; //在前面, 位于其他顶部窗口的后面 

        public const uint SC_MOVE = 0xF010; //移动
        public const uint SC_CLOSE = 0xF060;//关闭
         
        public const uint MF_BYCOMMAND = 0x00; //按命令方式
        public const uint MF_GRAYED = 0x00000001;    //灰掉
        public const uint MF_DISABLED = 0x00000002;  //不可用
        public const uint MF_ENABLED = 0x00000000;
         
        public const int WS_MINIMIZEBOX = 0x00020000; //最小化按钮
        public const int WS_MAXIMIZEBOX = 0x00010000; //最大化按钮
        public const int GWL_STYLE = -16;
        #endregion

        [DllImport("user32.dll")]
        public static extern IntPtr GetForegroundWindow();

        [DllImport("user32.dll")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("user32.dll")]
        public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);

        [DllImport("user32.dll")]
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);

        [DllImport("user32.dll")]
        public static extern int DeleteMenu(IntPtr hMenu, uint nPosition, uint wFlags);//删除菜单

        [DllImport("user32.dll")]
        public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);//获取系统菜单句柄

        [DllImport("user32.dll")]
        public static extern bool SetWindowLong(IntPtr hMenu, int nIndex, int dwNewLong);

        [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
        public static extern int GetWindowLong(IntPtr hwnd, int nIndex);

        [DllImport("user32.dll", SetLastError = true)]
        public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr GetModuleHandle(string lpModuleName);
    }
}
